package com.an.java.javaall.map;

import java.util.HashMap;
import java.util.Map;

public class TestMap {
    static int MAXIMUM_CAPACITY = 50000;
    public static void main(String[] args) {
        System.out.println(tableSizeFor(17));
        Map<String, String> map = new HashMap<>();
        System.out.println(map.put("d", "123"));
        System.out.println(map.put("d", "1233333"));
        System.out.println(map.put("d", "222222"));

    }

    static final int tableSizeFor(int cap) {
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
    }
}
